﻿using Common.Library;
using OnlineVideos.Data;
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;


namespace OnlineVideos.UI
{
    public static class QuizHelper
    {

        public static void SetQuizOptionCheckedState(string QuestionType, string UserAnswer, string CurrentOption, RadioButton rbOption, CheckBox cbOption)
        {
            try
            {
                bool OptionState = UserAnswer == CurrentOption;
                if (string.IsNullOrEmpty(QuestionType))
                {
                    cbOption.Visibility = Visibility.Collapsed;
                    rbOption.IsChecked = OptionState;
                }
                else
                {
                    rbOption.Visibility = Visibility.Collapsed;
                    cbOption.IsChecked = OptionState;
                }
            }
            catch (Exception ex)
            {
                
               Exceptions.SaveOrSendExceptions("Exception in SetQuizOptionCheckedState Method In QuizHelper.cs file", ex);
            }
        }

        public static void GetOptionChecked(RadioButton rbA, RadioButton rbB, RadioButton rbC, RadioButton rbD, CheckBox cbA, CheckBox cbB, CheckBox cbC, CheckBox cbD, string QuestionType)
        {
            try
            {
                string Answer = "";
                if (QuestionType == null)
                {
                    if (rbA.IsChecked == true)
                        Answer = "A";
                    if (rbB.IsChecked == true)
                        Answer = "B";
                    if (rbC.IsChecked == true)
                        Answer = "C";
                    if (rbD.IsChecked == true)
                        Answer = "D";
                }
                else
                {
                    if (cbA.IsChecked == true)
                        Answer = "A";
                    if (cbB.IsChecked == true)
                        Answer = "B" + "," + Answer;
                    if (cbC.IsChecked == true)
                        Answer = "C" + "," + Answer;
                    if (cbD.IsChecked == true)
                        Answer = "D" + "," + Answer;
                }
                if (Answer != "")
                {
                    SettingsHelper.Save("messagehighlight", "True");
                    QuizManager.SaveAnswersForWp8(Answer);
                }
            }
            catch (Exception ex)
            {
                
             Exceptions.SaveOrSendExceptions("Exception in GetOptionChecked Method In QuizHelper.cs file", ex);
            }
        }

        public static void SetQuizOptionColor(string QuestionType, string UserAnswer, string CorrectAnswer, string Option, TextBlock txtoption, TextBlock txtuserans, TextBlock txtcorrectans, Grid useransgrid, Grid correctansgrid, StackPanel stkcorrectans)
        {
            try
            {
                if (QuestionType == null)
                {
                    stkcorrectans.Visibility = Visibility.Collapsed;
                    if (UserAnswer != CorrectAnswer)
                    {
                        if (UserAnswer == Option)
                        {
                            txtoption.Foreground = new SolidColorBrush(Colors.Red);
                            txtoption.FontWeight = FontWeights.Normal;
                        }
                        else if (CorrectAnswer == Option)
                        {
                            txtoption.Foreground = new SolidColorBrush(Colors.Green);
                            txtoption.FontWeight = FontWeights.Bold;
                        }
                        else
                        {
                            txtoption.Foreground = new SolidColorBrush(Colors.White);
                            txtoption.FontWeight = FontWeights.Normal;
                        }
                    }
                    else
                    {
                        if (CorrectAnswer == Option)
                        {
                            txtoption.Foreground = new SolidColorBrush(Colors.Green);
                            txtoption.FontWeight = FontWeights.Bold;
                        }
                        else
                        {
                            txtoption.Foreground = new SolidColorBrush(Colors.White);
                            txtoption.FontWeight = FontWeights.Normal;
                        }
                    }
                }
                else
                {
                    if (UserAnswer == CorrectAnswer)
                    {
                        useransgrid.HorizontalAlignment = HorizontalAlignment.Left;
                        txtuserans.HorizontalAlignment = HorizontalAlignment.Left;
                        stkcorrectans.Children.Remove(correctansgrid);
                        useransgrid.Background = new SolidColorBrush(Colors.Green);
                        txtuserans.Text = UserAnswer;
                    }
                    else
                    {
                        useransgrid.Background = new SolidColorBrush(Colors.Red);
                        correctansgrid.Background = new SolidColorBrush(Colors.Green);
                        txtuserans.Text = UserAnswer;
                        txtcorrectans.Text = CorrectAnswer;
                    }
                    stkcorrectans.Visibility = Visibility.Visible;
                }
            }
            catch (Exception ex)
            {
                
                Exceptions.SaveOrSendExceptions("Exception in SetQuizOptionColor Method In QuizHelper.cs file", ex);
            }
        }
    }
}
